package com.autumn.sms.client;

import java.util.HashMap;
import java.util.Map;

import com.autumn.util.ExceptionUtils;
import com.autumn.validation.ValidationUtils;

/**
 * 
 * @author 老码农
 *
 *         2018-01-13 13:02:18
 */
public class SmsVerificationCodeMessage {
	private final String mobilePhone;
	private final String validateCode;
	private final int validateCodeType;
	private final Map<String, String> params;
	private String messageId;	

	/**
	 * 
	 * @param mobilePhone
	 *            手机号
	 * @param validateCodeType
	 *            验证码类型
	 * @param parameterName
	 *            码证参数名称
	 * @param validateCode
	 *            码证码
	 */
	public SmsVerificationCodeMessage(String mobilePhone, int validateCodeType, String parameterName,
			String validateCode) {
		this(mobilePhone, validateCodeType, validateCode, new HashMap<>());
		this.params.put(parameterName, validateCode);
	}

	/**
	 * 
	 * @param mobilePhone
	 *            手机号
	 * @param validateCodeType
	 *            验证码类型
	 * @param validateCode
	 *            码证码
	 * @param params
	 *            参数
	 */
	public SmsVerificationCodeMessage(String mobilePhone, int validateCodeType, String validateCode,
			Map<String, String> params) {
		super();
		this.mobilePhone = ExceptionUtils.checkNotNullOrBlank(mobilePhone, "mobilePhone");
		this.validateCode = ExceptionUtils.checkNotNullOrBlank(validateCode, "validateCode");
		if (!ValidationUtils.isMobilePhone(mobilePhone)) {
			ExceptionUtils.throwInvalidCastException(mobilePhone + " 不是有效的手机号码。");
		}
		this.validateCodeType = validateCodeType;
		if (params == null) {
			params = new HashMap<>();
		}
		this.params = params;
	}
	
	/**
	 * 
	* @return
	*
	 */
	public String getMessageId() {
		return messageId;
	}

	public void setMessageId(String messageId) {
		this.messageId = messageId;
	}

	/**
	 * 
	 * @return
	 *
	 */
	public String getMobilePhone() {
		return mobilePhone;
	}

	public String getValidateCode() {
		return validateCode;
	}

	public int getValidateCodeType() {
		return validateCodeType;
	}

	public Map<String, String> getParams() {
		return params;
	}

	/**
	 * 创建发送消息
	 * 
	 * @return
	 *
	 */
	public SmsSendMessage createSendMessage() {
		SmsSendMessage msg = new SmsSendMessage();
		msg.setMessageId(this.getMessageId());
		msg.setMobilePhone(this.getMobilePhone());
		msg.setParams(this.getParams());
		return msg;
	}
}
